package com.hong.atomic;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @Auther: Administrator
 * @Date: 2018/7/19 16:15
 * @Description:
 */
public class AtomicRefernceTest {

    public static void main(String[] args) {
        final AtomicReference<Simple> atomic  = new AtomicReference<Simple>(new Simple("Alex",12));
        System.out.println(atomic.get());

        boolean result = atomic.compareAndSet(new Simple("sdfs", 22), new Simple("sdfa", 234));
        System.out.println(result);

        JButton button = new JButton();

        //default
        final AtomicReference<Simple> s  = new AtomicReference<Simple>(new Simple("Alex",12));

        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                   //nivoke restful service
              //  s=new Simple("aaa",22);
                s.set(new Simple("qwe",22));
            }
        });
    }

    static class ObjectWrap<T>{
        private T t;

        public ObjectWrap(T t) {
            this.t = t;
        }

        public T getT() {
            return t;
        }

        public void setT(T t) {
            this.t = t;
        }
    }

    static class Simple{
        private String name;
        private int age;

        public Simple(String name,int age){
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }

}
